﻿using Batman.Maintenance.DTO.CreateForm;
using Batman.Maintenance.DTO.FormField;
using Batman.Maintenance.Utils;
using System;
using System.Linq.Expressions;

namespace Batman.Maintenance
{
    public static class MaintenanceCreateFormExtension
    {
        /// <summary>
        /// 设置新建表单的处理地址
        /// </summary>
        /// <param name="actionUrl"></param>
        public static MaintenanceCreateForm<T> SumitAction<T>(this MaintenanceCreateForm<T> createForm, string actionUrl)
        {
            createForm.Action = actionUrl;
            return createForm;
        }

        /// <summary>
        /// 新建表单字段
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="property"></param>
        /// <param name="formField"></param>
        public static MaintenanceCreateForm<T> HasFormField<T, TResult>(this MaintenanceCreateForm<T> createForm, Expression<Func<T, TResult>> property, MaintenanceFormField formField)
        {
            formField.FieldName = ExpressionUtil.GetSmallHumpWord(property);
            createForm.Fields.Add(formField);

            return createForm;
        }

    }
}
